<template>
  <el-container class="main_con" style="padding-bottom:0px">
    <ufrom @submit="saveData" ref="ufrom">
      <el-form size="medium" label-width="100px">
        <div class="setting_body_item">
          <div class="header">积分设置</div>
          <div class="conetnt edit_con">
            <div class="edit_content">
              <el-form-item label="积分文字"><el-input v-model="obj.configuration.integral_text" style="width:360px;" maxlength="4" show-word-limit></el-input></el-form-item>
              <el-form-item label="是否开启">
                <el-radio-group v-model="obj.configuration.is_open">
                  <el-radio :label="1">开启</el-radio>
                  <el-radio :label="0">关闭</el-radio>
                </el-radio-group>
              </el-form-item>

              <el-form-item label="积分上限">
                <el-radio-group v-model="obj.configuration.integral_upper">
                  <el-radio :label="0">不限制</el-radio>
                  <el-radio :label="1">自定义</el-radio>
                </el-radio-group>
              </el-form-item>

              <el-form-item label="" v-if="obj.configuration.integral_upper == 1">
                <div class="fks">
                  账户最大可以获得
                  <el-input v-model="obj.configuration.integral_upper_limit" style="width:180px;margin-right:10px;margin-left:10px;">
                    <template slot="append">
                      积分
                    </template>
                  </el-input>
                  <div style="color:#909399;font-size:12px;">用户积分大于等于此值时将无法继续增加，后台手动充值不限制，已持有积分不限制</div>
                </div>
              </el-form-item>
            </div>
          </div>
        </div>

        <div class="setting_body_item">
          <div class="header">余额设置</div>
          <div class="conetnt edit_con">
            <div class="edit_content">
              <el-form-item label="余额文字"><el-input v-model="obj.configuration.balance_text" style="width:360px;" maxlength="4" show-word-limit></el-input></el-form-item>

              <el-form-item label="充值设置">
                <el-radio-group v-model="obj.configuration.balance_setting">
                  <el-radio :label="1">开启</el-radio>
                  <el-radio :label="0">关闭</el-radio>
                </el-radio-group>
              </el-form-item>

              <el-form-item label="" v-if="obj.configuration.balance_setting == 1">
                <div class="fks">
                  系统允许最低充值金额
                  <el-input v-model="obj.configuration.balance_cash" style="width:180px;margin-left:10px">
                    <template slot="append">
                      元
                    </template>
                  </el-input>
                  <div style="color:#909399;font-size:12px;">账户充值时，最低允许的充值金额，系统最低可支持0.1元</div>
                </div>
              </el-form-item>

              <el-form-item label="余额提现">
                <el-radio-group v-model="obj.configuration.withdraw">
                  <el-radio :label="1">开启</el-radio>
                  <el-radio :label="0">关闭</el-radio>
                </el-radio-group>
              </el-form-item>

              <el-form-item label="线上提现方式">
                <el-checkbox-group v-model="obj.configuration.withdraw_type">
                  <el-checkbox label="1">微信钱包</el-checkbox>
                  <!-- <el-checkbox label="2">支付宝</el-checkbox> -->
                </el-checkbox-group>
              </el-form-item>
              <el-form-item label="线下提现方式">
                <el-checkbox-group v-model="obj.configuration.withdraw_type_outline">
                  <el-checkbox label="1">微信</el-checkbox>
                  <el-checkbox label="2">支付宝</el-checkbox>
                  <el-checkbox label="3">银行卡</el-checkbox>
                </el-checkbox-group>
              </el-form-item>
              <el-form-item label="提现限制">
                <el-radio-group v-model="obj.configuration.withdraw_limit">
                  <el-radio :label="0">不限制</el-radio>
                  <el-radio :label="1">自定义</el-radio>
                </el-radio-group>
              </el-form-item>

              <el-form-item label="" v-if="obj.configuration.withdraw_limit == 1">
                <div class="fks">
                  余额满
                  <el-input v-model="obj.configuration.withdraw_limit_cash" style="width:180px;margin-right:10px;margin-left:10px">
                    <template slot="append">
                      元
                    </template>
                  </el-input>
                  可提现
                </div>
              </el-form-item>

              <el-form-item label="提现手续费">
                <el-radio-group v-model="obj.configuration.withdraw_service">
                  <el-radio :label="0">不扣除</el-radio>
                  <el-radio :label="1">自定义</el-radio>
                </el-radio-group>
              </el-form-item>

              <el-form-item label="" v-if="obj.configuration.withdraw_service == 1">
                <div class="fks">
                  <div style="margin-bottom:10px;">
                    手续费
                    <el-input v-model="obj.configuration.service_charge" style="width:180px;margin-right:10px;margin-left:10px">
                      <template slot="append">
                        %
                      </template>
                    </el-input>
                  </div>
                  <div style="margin-bottom:10px;">
                    <div style="display:inline-block;width:60px;">免手续费</div>
                    <el-radio-group v-model="obj.configuration.is_free_fee" style="margin-left:10px;">
                      <el-radio :label="0">不免手续费</el-radio>
                      <el-radio :label="1">自定义免手续费区间</el-radio>
                    </el-radio-group>
                  </div>
                  <div v-if="obj.configuration.is_free_fee == 1">
                    <div style="display:inline-block;width:60px;">&nbsp;</div>
                    <el-input v-model="obj.configuration.free_fee_section[0]" style="width:180px;margin-right:10px;">
                      <template slot="append">
                        元
                      </template>
                    </el-input>
                    -
                    <el-input v-model="obj.configuration.free_fee_section[1]" style="width:180px;margin-right:10px;margin-left:10px;">
                      <template slot="append">
                        元
                      </template>
                    </el-input>
                    时不扣除手续费
                    <div style="color:#909399;font-size:12px;margin-left:60px;line-height:24px;margin-top:10px;">
                      当手续费金额在此区间内时，不扣除手续费，结束金额 必须大于 开始金额。
                      <br />
                      例如 设置开始金额0元 结束金额5元，只有手续费金额高于5元时，才扣除
                    </div>
                  </div>
                </div>
              </el-form-item>
            </div>
          </div>
        </div>
        <div class="setting_body_item">
          <div class="header">分销提现设置</div>
          <div class="conetnt edit_con">
            <div class="edit_content">
              <el-form-item label="分销提现">
                <el-radio-group v-model="obj.configuration.agent_withdraw">
                  <el-radio :label="1">开启</el-radio>
                  <el-radio :label="0">关闭</el-radio>
                </el-radio-group>
              </el-form-item>
              <el-form-item label="线上提现方式">
                <el-checkbox-group v-model="obj.configuration.agent_withdraw_type">
                  <el-checkbox label="1">微信钱包</el-checkbox>
                  <el-checkbox label="2">余额</el-checkbox>
                </el-checkbox-group>
              </el-form-item>
              <el-form-item label="线下提现方式">
                <el-checkbox-group v-model="obj.configuration.agent_withdraw_type_outline">
                  <el-checkbox label="1">微信</el-checkbox>
                  <el-checkbox label="2">支付宝</el-checkbox>
                  <el-checkbox label="3">银行卡</el-checkbox>
                </el-checkbox-group>
              </el-form-item>
              <el-form-item label="提现限制">
                <el-radio-group v-model="obj.configuration.agent_withdraw_limit">
                  <el-radio :label="0">不限制</el-radio>
                  <el-radio :label="1">自定义</el-radio>
                </el-radio-group>
              </el-form-item>
              <el-form-item label="" v-if="obj.configuration.agent_withdraw_limit == 1">
                <div class="fks">
                  分销余额满
                  <el-input v-model="obj.configuration.agent_withdraw_limit_cash" style="width:180px;margin-right:10px;margin-left:10px">
                    <template slot="append">
                      元
                    </template>
                  </el-input>
                  可提现
                </div>
              </el-form-item>

              <el-form-item label="提现手续费">
                <el-radio-group v-model="obj.configuration.agent_withdraw_service">
                  <el-radio :label="0">不扣除</el-radio>
                  <el-radio :label="1">自定义</el-radio>
                </el-radio-group>
              </el-form-item>

              <el-form-item label="" v-if="obj.configuration.agent_withdraw_service == 1">
                <div class="fks">
                  <div style="margin-bottom:10px;">
                    手续费
                    <el-input v-model="obj.configuration.agent_service_charge" style="width:180px;margin-right:10px;margin-left:10px">
                      <template slot="append">
                        %
                      </template>
                    </el-input>
                  </div>
                  <div style="margin-bottom:10px;">
                    <div style="display:inline-block;width:60px;">免手续费</div>
                    <el-radio-group v-model="obj.configuration.agent_is_free_fee" style="margin-left:10px;">
                      <el-radio :label="0">不免手续费</el-radio>
                      <el-radio :label="1">自定义免手续费区间</el-radio>
                    </el-radio-group>
                  </div>
                  <div v-if="obj.configuration.agent_is_free_fee == 1">
                    <div style="display:inline-block;width:60px;">&nbsp;</div>
                    <el-input v-model="obj.configuration.agent_free_fee_section[0]" style="width:180px;margin-right:10px;">
                      <template slot="append">
                        元
                      </template>
                    </el-input>
                    -
                    <el-input v-model="obj.configuration.agent_free_fee_section[1]" style="width:180px;margin-right:10px;margin-left:10px;">
                      <template slot="append">
                        元
                      </template>
                    </el-input>
                    时不扣除手续费
                    <div style="color:#909399;font-size:12px;margin-left:60px;line-height:24px;margin-top:10px;">
                      当手续费金额在此区间内时，不扣除手续费，结束金额 必须大于 开始金额。
                      <br />
                      例如 设置开始金额0元 结束金额5元，只有手续费金额高于5元时，才扣除
                    </div>
                  </div>
                </div>
              </el-form-item>
            </div>
          </div>
        </div>
        <div class="setting_body_item">
          <div class="header">商户余额提现</div>
          <div class="conetnt edit_con">
            <div class="edit_content">
              <el-form-item label="商户余额提现">
                <el-radio-group v-model="obj.configuration.merchant_withdraw">
                  <el-radio :label="1">开启</el-radio>
                  <el-radio :label="0">关闭</el-radio>
                </el-radio-group>
              </el-form-item>

              <el-form-item label="线上提现方式">
                <el-checkbox-group v-model="obj.configuration.merchant_withdraw_type">
                  <el-checkbox label="1">微信钱包</el-checkbox>
                  <el-checkbox label="2">余额</el-checkbox>
                </el-checkbox-group>
              </el-form-item>
              <el-form-item label="线下提现方式">
                <el-checkbox-group v-model="obj.configuration.merchant_withdraw_type_outline">
                  <el-checkbox label="1">微信</el-checkbox>
                  <el-checkbox label="2">支付宝</el-checkbox>
                  <el-checkbox label="3">银行卡</el-checkbox>
                </el-checkbox-group>
              </el-form-item>
              <el-form-item label="提现限制">
                <el-radio-group v-model="obj.configuration.merchant_withdraw_limit">
                  <el-radio :label="0">不限制</el-radio>
                  <el-radio :label="1">自定义</el-radio>
                </el-radio-group>
              </el-form-item>
              <el-form-item label="" v-if="obj.configuration.merchant_withdraw_limit == 1">
                <div class="fks">
                  分销余额满
                  <el-input v-model="obj.configuration.merchant_withdraw_limit_cash" style="width:180px;margin-right:10px;margin-left:10px">
                    <template slot="append">
                      元
                    </template>
                  </el-input>
                  可提现
                </div>
              </el-form-item>

              <el-form-item label="提现手续费">
                <el-radio-group v-model="obj.configuration.merchant_withdraw_service">
                  <el-radio :label="0">不扣除</el-radio>
                  <el-radio :label="1">自定义</el-radio>
                </el-radio-group>
              </el-form-item>

              <el-form-item label="" v-if="obj.configuration.merchant_withdraw_service == 1">
                <div class="fks">
                  <div style="margin-bottom:10px;">
                    手续费
                    <el-input v-model="obj.configuration.merchant_service_charge" style="width:180px;margin-right:10px;margin-left:10px">
                      <template slot="append">
                        %
                      </template>
                    </el-input>
                  </div>
                  <div style="margin-bottom:10px;">
                    <div style="display:inline-block;width:60px;">免手续费</div>
                    <el-radio-group v-model="obj.configuration.merchant_is_free_fee" style="margin-left:10px;">
                      <el-radio :label="0">不免手续费</el-radio>
                      <el-radio :label="1">自定义免手续费区间</el-radio>
                    </el-radio-group>
                  </div>
                  <div v-if="obj.configuration.merchant_is_free_fee == 1">
                    <div style="display:inline-block;width:60px;">&nbsp;</div>
                    <el-input v-model="obj.configuration.merchant_free_fee_section[0]" style="width:180px;margin-right:10px;">
                      <template slot="append">
                        元
                      </template>
                    </el-input>
                    -
                    <el-input v-model="obj.configuration.merchant_free_fee_section[1]" style="width:180px;margin-right:10px;margin-left:10px;">
                      <template slot="append">
                        元
                      </template>
                    </el-input>
                    时不扣除手续费
                    <div style="color:#909399;font-size:12px;margin-left:60px;line-height:24px;margin-top:10px;">
                      当手续费金额在此区间内时，不扣除手续费，结束金额 必须大于 开始金额。
                      <br />
                      例如 设置开始金额0元 结束金额5元，只有手续费金额高于5元时，才扣除
                    </div>
                  </div>
                </div>
              </el-form-item>
            </div>
          </div>
        </div>
      </el-form>
    </ufrom>
  </el-container>
</template>

<script>
import {addSiteConfig, editSiteConfig, getSiteConfig} from '@/api/mall/setting';
export default {
  data() {
    return {
      isLoading: false,
      obj: {
        type: 'integralBalance',
        status: 1,
        configuration: {
          integral_text: '',
          integral_upper: 0,
          integral_upper_limit: 0,
          is_open: 0,
          balance_text: '',
          balance_setting: 0,
          balance_cash: 0.1,
          withdraw: 1,
          withdraw_type: [],
          withdraw_type_outline: [],
          withdraw_limit: 1,
          withdraw_limit_cash: '100.00',
          withdraw_service: 0,
          service_charge: 5.5,
          is_free_fee: 0,
          free_fee_section: [0, 0],
          agent_withdraw: 1,
          agent_withdraw_type: [],
          agent_withdraw_type_outline: [],
          agent_withdraw_limit: 0,
          agent_withdraw_limit_cash: '100.00',
          agent_withdraw_service: 0,
          agent_service_charge: 5.5,
          agent_is_free_fee: 0,
          agent_free_fee_section: [0, 0],
          merchant_withdraw: 1,
          merchant_withdraw_type: [],
          merchant_withdraw_type_outline: [],
          merchant_withdraw_limit: 0,
          merchant_withdraw_limit_cash: '100.00',
          merchant_withdraw_service: 0,
          merchant_service_charge: 5.5,
          merchant_is_free_fee: 0,
          merchant_free_fee_section: [0, 0]
        }
      }
    };
  },
  components: {},
  mounted() {
    this.getConfig('integralBalance');
  },
  methods: {
    //获取站点配置数据
    getConfig(type) {
      getSiteConfig(type)
        .then(res => {
          if (res.msg) {
            this.obj = res.msg;
          }
        })
        .catch(e => {});
    },
    //保存数据
    saveData() {
      if (this.obj.update_time) {
        //更新
        editSiteConfig(this.obj)
          .then(res => {
            this.$refs.ufrom.init();
            this.getConfig('integralBalance');
          })
          .catch(e => {
            this.$refs.ufrom.init();
          });
      } else {
        //新增
        addSiteConfig(this.obj)
          .then(res => {
            this.$refs.ufrom.init();
            this.getConfig('integralBalance');
          })
          .catch(e => {
            this.$refs.ufrom.init();
          });
      }
    }
  }
};
</script>

